package edu.java.homework.hw03.ipj07;

import java.util.Arrays;
import java.util.Scanner;

public class Exer05 {

    public static void main(String[] args) {
	String[] strInts = null;
	int count = 0;
	Scanner input = new Scanner(System.in);
	System.out.println("Please, enter the count of numbers: ");
	count = input.nextInt();
	if (count <= 0) {
	    throw new IllegalArgumentException(
		    "Error! The count of numbers would be 1 or more.");
	}
	strInts = new String[count];

	// input the numbers
	int[] ints = inputNumbers(strInts);
	System.out.println(Arrays.toString(ints));
	System.out.println("\nThe average of the numbers is: " + average(ints));

	input.close();
    }

    public static int[] inputNumbers(String[] strInts) {
	if (strInts == null) {
	    throw new IllegalArgumentException(
		    "Error! The string of integer numbers is null-pointed");
	}
	
	Scanner input= new Scanner(System.in);
	int length=strInts.length;
	int[] numbs= new int[length];
	for(int i=0;i<length;i++){
	    System.out.print("number[" + i + "]= ");
	    strInts[i]= input.nextLine();
	    numbs[i]=Integer.parseInt(strInts[i]);
	}
	
	input.close();
	return numbs;
    }
    
    public static double average(int[] ints){
	if(ints==null){
	    throw new IllegalArgumentException("Null-pointed array.");
	}
	int length=ints.length;
	double sum=0;
	for(int i=0;i<length;i++){
	    sum+=ints[i];
	}
	return (sum/length);
    }

}
